package com.jf.mall.service;

import com.jf.mall.dao.UserDAO;
import com.jf.mall.dao.impl.UserDAOImpl;
import com.jf.mall.domain.User;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-09-23
 * Time:17:40
 */
public class UserService {
    private final UserDAO userDAO = new UserDAOImpl();

    /**
     * 注册用户
     * @param user User对象
     * @return 成功返回true, 失败返回false
     */
    public boolean register(User user) {
        return userDAO.saveUser(user) == 1;
    }

    /**
     * 查询用户名是否已存在
     * @param username 用户名
     * @return 存在返回true, 不存在返回false
     */
    public boolean checkExistUser(String username) {
        return userDAO.queryUserByUsername(username) != null;
    }

    /**
     * 登录用户
     * @param tempUser 临时用户
     * @return User对象, 不存在用户返回null
     */
    public User login(User tempUser) {
        return userDAO.queryUserByUsernameAndPassword(tempUser.getUsername(), tempUser.getPassword());
    }
    public User loginAdmin(User tempUser) {
        return userDAO.queryUserByUsernameAndPassword(tempUser.getUsername(), tempUser.getPassword(), true);
    }
}
